package com.woniu.dao.impl;

import com.woniu.dao.UserDao;
import com.woniu.entity.User;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author:陈涵
 * @Do:静态代理，通过我们手动去实现代理类
 * 问题：
 * 1.写死不灵活
 * 2.只能代理一个接口
 * 3.代码量大
 * @date: 2022/8/24 18:10
 */
public class UserDaoImpl implements UserDao {
    private SqlSession sqlSession;

    public void setSqlSession(SqlSession sqlSession) {
        this.sqlSession = sqlSession;
    }

    @Override
    public User findOne(int id) {
        UserDao userDao=sqlSession.getMapper(UserDao.class);
        return userDao.findOne(id);
    }

    @Override
    public List<User> findAll() {
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        return mapper.findAll();
    }

    @Override
    public int addOne(User user) {
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        return mapper.addOne(user);
    }

    @Override
    public int updateOne(User user) {
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        return mapper.updateOne(user);
    }

    @Override
    public int deleteOne(int id) {
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        return mapper.deleteOne(id);
    }
}
